package com.kaoshi.management.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kaoshi.common.config.Result;
import com.kaoshi.management.pojo.XtSlideshow;
import com.kaoshi.management.service.XtSlideshowService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-30
 */
@RestController
@CrossOrigin
@RequestMapping("/xt-slideshow")
public class XtSlideshowController {

    @Autowired
    private XtSlideshowService xtSlideshowService;

    @RequestMapping("/dd/{current}/{pageSize}")
    public Result findAll(@PathVariable Integer current,
                          @PathVariable Integer pageSize,
                          @RequestBody XtSlideshow xtSlideshow) {

        Page<XtSlideshow> page = xtSlideshowService.findAll(current, pageSize, xtSlideshow);
        return Result.ok(page);
    }

    @RequestMapping("/change")
    public Result change(@RequestBody XtSlideshow xtSlideshow) {
        if(xtSlideshow.getId() == null){
            xtSlideshow.setPublisher("李明明");
            xtSlideshowService.save(xtSlideshow);
            return Result.ok("添加成功");
        }else {
            xtSlideshowService.updateById(xtSlideshow);
            return Result.ok("修改成功");
        }
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        xtSlideshowService.removeById(id);
        return Result.ok("删除成功");
    }

}
